<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>xxxx</title>
    <script src="./js/wsj-form-validate.js"></script>
</head>
<body>
   <input type="number" class="ipt"  placeholder="请输入手机号" name="phone" id="phone">
   <input type="text" class="ipt" placeholder="验证码" name="cell_captch" id="cell_captch">
<script>

var config_step1 = [
    {
        el: 'phone',
        handle: "blur",
        reg: ["cellphone"],
        msg: ["手机号格式错误"],
        success: function (curObj) {
            document.getElementById('err_cellphone').innerHTML=''
        },
        fail: function (curObj, idx) {
            document.getElementById('err_cellphone').innerHTML=curObj.msg[idx]
        }
    }
]

var config_step2=[
    {
        el: 'cell_captch',
        handle: "blur",
        reg: ["int46"],
        msg: ["短信验证码错误"],
        success: function (curObj) {
            document.getElementById('err_sms_captcha').innerHTML=''
        },
        fail: function (curObj, idx) {        
            document.getElementById('err_sms_captcha').innerHTML=curObj.msg[idx]
        }
    }
]

WsjFormReg.prototype.reg.int4 = function (that) {
    return /^\d{4}$/.test(that.value)
}
WsjFormReg.prototype.reg.int6 = function (that) {
    return /^\d{6}$/.test(that.value)
}
WsjFormReg.prototype.reg.int46 = function (that) {
    return /^\d{4,6}$/.test(that.value)
}
var regResult1 = new WsjFormReg(config_step1)
var regResult2 = new WsjFormReg(config_step2)



//输入手机号以后,点击获取短信验证码
$('#btn_captch').click(function () {
    if(!regResult1.checkAllStatus()){return}
        closezz('#btn_captch', '获取验证码', 20)
        $.ajax({
            url: "/xuetang_auth/libao/getVerifyCode",
            type: 'post',
            dataType: 'json',
            data: {
              mobile: $('#phone').val()
            },
            success: function (data, textStatus, xhr) {
                if(data.status!=1){
                    wern.note(data.msg,{color:'danger',center:1,full:1})
                }
            }
        });
})

//提交手机号和短信验证码
$('#btn_linqu').click(function () {
    if(!regResult2.checkAllStatus()){return}
        closezz('#btn_linqu', '立即领取', 20)
        $.ajax({
            url: "/xuetang_auth/libao/fetchLiBao",
            type: 'post',
            dataType: 'json',
            data: {
              code: $('#cell_captch').val(),
              "project":"tbl_research_1w_zhibo"
            },
            success: function (data, textStatus, xhr) {
                if(data.status==1){
                  document.getElementById('pop_gift').style.display='block'
                }else{
                  wern.note(data.msg,{color:'danger',center:1,full:1})
                }
            }
        });
})

$('[type=number]').keyup(function () {
    $(this).val().replace(/[^\d]/g, '')
})

function closezz(eleId, desc, count) {
    CountDown()//立即执行一次，否则点击按钮后要过1秒才会执行
    var countdown = setInterval(CountDown, 1000);
    function CountDown() {
        $(eleId).prop("disabled", true).html("(" + count + ")").addClass('disab');
        if (count <= -1) {
            $(eleId).html(desc).removeClass('disab').prop("disabled", false);
            clearInterval(countdown);
        }
        count--;
    }
}


 //获取网址get参数
 function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}

    </script>
</body>